package org.lanqiao.dxzf.controller.account;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.lanqiao.dxzf.entity.Account;
import org.lanqiao.dxzf.entity.Fee;
import org.lanqiao.dxzf.entity.Paging;
import org.lanqiao.dxzf.service.account.AccountService;
import org.lanqiao.dxzf.util.StringCut;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;



@Controller
public class AccountController {
	
	@Resource
	AccountService accountService;
	
	@RequestMapping("account_list")
	public String account_list(Paging paging,HttpServletRequest request) {
		List<Account> listaccount = accountService.account_list();
		if (paging.getCurrentPage() == null){
	    	paging.setCurrentPage(1);
	    } else {
	    	paging.setCurrentPage(paging.getCurrentPage());
	    }
	    //设置每页数据为十条
	    paging.setPageSize(6);
	    //每页的开始数
	    paging.setStar((paging.getCurrentPage() - 1) * paging.getPageSize());
	    //list的大小
	    int count = listaccount.size();
	    //设置总页数
	    paging.setTotalPage(count % 6 == 0 ? count / 6 : count / 6 + 1);
	    //对list进行截取
	    paging.setDataList(listaccount.subList(paging.getStar(),count-paging.getStar()>paging.getPageSize()?paging.getStar()+paging.getPageSize():count));
	    //设置作用域
	    request.setAttribute("paging", paging);
		return "account/account_list";
	}
	/**
	 * 查看账务账号详细信息
	 * @param request
	 * @return
	 */
	@RequestMapping("/account_detail")
	public String account_detail(HttpServletRequest request) {
		int fin_id = Integer.valueOf(request.getParameter("fin_id"));
		Account account= new Account();
		account.setFin_id(fin_id);
		account = accountService.select_account_list(account);
		System.out.println("::::::::::::::::"+account.getCid());
		request.setAttribute("account", account);
		return "account/account_detail";
	}
	/**
	 * 进入账务账号修改界面
	 * @param request
	 * @return
	 */
	@RequestMapping("/account_modi")
	public String account_modi(HttpServletRequest request) {
		int fin_id = Integer.valueOf(request.getParameter("fin_id"));
		Account account= new Account();
		account.setFin_id(fin_id);
		account = accountService.select_account_list(account);
		request.setAttribute("account", account);
		return "account/account_modi";
	}
	/**
	 * 账务账号修改提交
	 * @param account
	 * @param request
	 * @return
	 */
	@RequestMapping("account_modi_alter")
	public String account_modi_alter(Account account,HttpServletRequest request) {
		int i = -1;
	    i = accountService.upadte_Customer_list(account);
	    System.out.println(account.getCid());
		System.out.println(i+":::::::::::::::::"+account.getCname());
		System.out.println(i+":::::::::::::::::"+account.getContact_address());
		System.out.println(i+":::::::::::::::::"+account.getPostcode());
		System.out.println(i+":::::::::::::::::"+account.getQq());
		request.setAttribute("account",account);
		if(i>0) {
			request.setAttribute("update", "yes");
			return "account/account_modi";
		}else {
			request.setAttribute("update", "no");
			return "account/account_modi";
		}
	}
	/**
	 * 跳转到账务账号添加页面
	 * @return
	 */
	@RequestMapping("account_add_show")
	public String account_add_show() {
		return "account/account_add";
	}
	
/*	@RequestMapping("account_add")
	public String account_add(Account account,HttpServletRequest request) {
		accountService.insert_accounts(account);
		return "account/account_add";
	}*/
}
